<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>promise</title>
</head>
<body>
    
    <script>
    
        let p1 = new Promise((resolve,reject)=>{
            resolve('this is p1')
        });

        let p2 = new Promise((resolve,reject)=>{
            resolve('this is p2')
        });

        let p3 = new Promise((resolve,reject)=>{
            resolve('this is p3')
        });

        let p4 = new Promise((resolve,reject)=>{
            resolve('this is p4')
        });

        let p5 = new Promise((resolve,reject)=>{
            resolve('this is p5')
        });

        let promises = [p1,p2,p3,p4,p5];

        /* promises.forEach(promise=>{
            promise.then(res=>{
                console.log(res);
            }).catch(e=>{
                if(e)return;
            })
        }) */

        for(var i=0;i<promises.length;i++){
            (function (i) {
                var ele = promises[i];
                setTimeout(() => {
                    ele.then(res=>{
                        console.log(res);
                    })
                }, 1000*i);
            })(i);
        }
        /* Promise.all(promises).then(data=>{console.log(data);}) */

        
    
    </script>

</body>
</html>